<template>
    <div style="padding:20px">
  
        <div style="margin-bottom:15px">
      <el-input
        v-model="queryParams.faultNo"
        placeholder="请输入工单号"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="queryBtn"
      />
      <el-input
        v-model="queryParams.lockMac"
        placeholder="请输入编号"
        style="width: 200px;margin-left:5px"
        class="filter-item"
        @keyup.enter.native="queryBtn"
      />
      <el-input
        v-model="queryParams.lockName"
        placeholder="请输入站点名称"
        style="width: 200px;margin-left:5px"
        class="filter-item"
        @keyup.enter.native="queryBtn"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        style="margin-left: 5px"
        @click="queryBtn"
      >
        查询
      </el-button>

      <span style="float: right;
    margin-right: 20px;
    font-weight: 600;color: #494949;">当前账号：<span style="color: #ff770f;">{{title}}</span></span>

        </div>
     
      <el-row>
        <el-col :span="24">

     <el-table
      :header-cell-style="{ background: '#ffffff', color: '#000000' }"
      ref="lcredepositrequestTable"
      :key="tableKey"
      :row-class-name="tableRowClassName"
      v-loading="loading"
      :data="list"
      :stripe="true"
      border
      fit
      highlight-current-row
      style="
        width: 100%;
        font-size: 15px;
        box-shadow: 1px 1px 8px #cdcdcd;
        border: 0px;
      "
      @sort-change="sortChange"
    >
          <!-- <el-table ref="lcredepositrequestTable" v-loading="loading" :data="list" :stripe="true" :row-key="'id'" :max-height="clientHeight" :height="clientHeight" @selection-change="handleTableChange"> -->
           
            <el-table-column prop="lockMac" label="编号" width="120" sortable align="center">
            </el-table-column>
            <el-table-column prop="lockName" label="站点名称" width="240" sortable align="center">
            </el-table-column>
            <el-table-column prop="faultDesc" label="问题描述" width="135" align="center">
            </el-table-column>
            <el-table-column prop="procMethod" label="解决方案" width="138" align="center">
            </el-table-column>
            <el-table-column prop="procDate" label="维修日期" width="180" align="center">
            </el-table-column>
            <el-table-column prop="isProced;" label="处理状态" width="120" align="center">
           <template slot-scope="{ row }">
          <el-tag
            v-if="row.isProced == 0"
            size="medium"
            type="danger"
            effect="dark"
            style="font-size: 14px"
            >未处理</el-tag
          >
          <el-tag
            v-else-if="row.isProced == 1"
            size="medium"
            type="success"
            effect="dark"
            style="font-size: 14px"
            >已处理</el-tag
          >
          <el-tag v-else size="medium" type="Info" style="font-size: 14px">{{
            row.isReport
          }}</el-tag>
           </template>
            </el-table-column> 

        <el-table-column prop="livePic" label="图片" width="120" align="center">
        <el-button type="primary" size="mini" @click="handleUpdate(row)">
           查看
         </el-button>
            </el-table-column>
           
            <el-table-column prop="createDate" label="报修时间" width="180" align="center">
            </el-table-column>
            <el-table-column prop="repairPersonFact" label="实际维修人员" width="180" align="center">
            </el-table-column>
            <el-table-column prop="repairPerson" label="维修人员" width="240" align="center">
            </el-table-column>
            <el-table-column prop="faultNo" label="工单号" width="210" align="center">
            </el-table-column>  

            <!-- <el-table-column label="编辑" width="140" fixed="right" align="center">
            <template slot-scope="scope">
            <el-button :disabled="userState" class="operateBtn" size="mini" type="primary" @click="editBtn2(scope.$index, scope.row)" title="编辑"><i class="el-icon-edit-outline"></i></el-button>
            </template>
            </el-table-column> -->
           

          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" class="page-tool">
          <el-pagination layout="total,sizes,prev, pager,next,jumper" :page-size="pageSize" :total="total" :page-sizes="[10, 20, 30, 40]" @size-change="handlePageChange" @current-change="handleNoChange">
          </el-pagination>
        </el-col>
      </el-row>
  

      <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" center width="1590px">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-position="left"
        label-width="70px"
      >
        <el-image 
            style="width:1536px;height:864px;"
            :src="url" 
            :preview-src-list="srcList">
            <div slot="error" class="image-slot" style="text-align:center">
                暂无图片
            </div>
        </el-image>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false"> 关闭 </el-button>
      </div>
    </el-dialog>


    
    <el-dialog
      title="编辑"
      :visible.sync="addDialog2"
      :width="'800px'"
      :destroy-on-close="true"
    >
      <el-form :model="feeForm" ref="feeForm">
       
        <el-row>
          <el-col span="11">
            <el-form-item label="工单号" :label-width="labelWidth">
              <el-input
                v-model="feeForm.faultNo"
                disabled
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item
              label="点位"
              :label-width="labelWidth"
            >
              <el-input
                v-model="feeForm.lockMac"
                disabled
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col span="11">
            <el-form-item
              label="站点名称"
              :label-width="labelWidth"
              prop="lockName"
            >
              <el-input
                v-model="feeForm.lockName"
                disabled
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col span="12">
            <el-form-item
             
              label="维修日期"
              :label-width="labelWidth"
              prop="procDate"
            >
              <el-input
                disabled
                v-model="feeForm.procDate"
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col>

         


        </el-row>
        <el-row>
          <el-col span="11">
            <el-form-item
              label="创建时间"
              :label-width="labelWidth"
              prop="createDate"
            >
              <el-input
                disabled
                v-model="feeForm.createDate"
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col> 
          

        </el-row>

        <el-row>

        <el-col span="18">
            <el-form-item
              label="问题描述"
              :label-width="labelWidth"
              prop="faultDesc"
            >
            <el-input
                v-model="feeForm.faultDesc"
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 5}"
                placeholder="请输入内容"
              ></el-input>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col span="18">
            <el-form-item
              label="解决方案"
              :label-width="labelWidth"
              prop="procMethod"
            >
            <el-input
                v-model="feeForm.procMethod"
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 5}"
                placeholder="请输入内容"
              ></el-input>
             
            </el-form-item>
          </el-col> 
          

        </el-row>

      <el-row>
          <el-col span="12">
            <el-form-item label="处理状态" :label-width="labelWidth">

              <el-select v-model="feeForm.isProced" placeholder="请选择类型" @change="handleChangeType(form.type)">
            <el-option key="0" label="未处理" :value="0"></el-option>
            <el-option key="1" label="已处理" :value="1"></el-option>
          </el-select>

           </el-form-item>
          </el-col>
          
        </el-row>
        <el-row>
        <el-col span="12">
            <el-form-item
             
              label="维修人员"
              :label-width="labelWidth"
              prop="repairPerson"
            >
              <el-input
                v-model="feeForm.repairPerson"
                auto-complete="off"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
       

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancle2">取消</el-button>
        <el-button type="primary" @click="Channelcheck2">修改</el-button>
      </div>
    </el-dialog>
  
  </div>
  </template>
  
  <script>
   
  import { } from "../../utils/auth";
  import { deviceRepairApi,updateLcRepairProcApi } from "@/api/deviceRepair";

  
  export default {
    name: "deviceRepair",
    data: function () {
      return {
        clientHeight:
          Math.max(
            document.documentElement.scrollHeight,
            document.body.scrollHeight
          ) -
          132 -
          5 +
          10 -
          28,
        labelWidth: "100px",
        loading: false,
        dialogTitle: "",
        pageNo: 1,
        pageSize:20,
        statusOptions:['一步运维','管理员运维平台','运营商管理平台'],
        statusOptions2:['设备操作','规格修改'],
        total: 0,
        addDialog2:false,
        list:[],
        multipleSelection: [],
        dialogFormVisible:false,
        dialogStatus: "",
        feeForm:'',
        textMap: {
        update: "查看",
         create: "查看",
        },
        lcredepositrequests: [],
        form: {
          
        },
        roleCode:'',
        queryParams:{
          faultNo:'',
          lockMac:'',
          lockName:'',
          faultSource:'',
          procRate:'',
          isReport:''
        },
        addDialog:false,
        parkfieldList: [],
        parkfieldId: '',
        status: '',
  
      };
    },
    methods: {
      editBtn (index, row) {
        let _this = this;
        _this.$nextTick(()=>{
          if(_this.$refs.form != undefined){
            _this.$refs.form.resetFields();
          }
        });
        _this.feeForm = row;
        _this.addDialog = true;
      },
      
      editBtn2 (index, row) {
      let _this = this;
      _this.$nextTick(()=>{
        if(_this.$refs.form != undefined){
          _this.$refs.form.resetFields();
        }
      });
      _this.feeForm = row;
      _this.addDialog2 = true;
    },


      procRefund (index, row, status) {
        let _this = this;
        _this.loading = true;
        procRefundApi(row.id, status).then(resp => {
          console.log(resp)
          _this.loadAbnormalOrder(this.pageNo, this.pageSize);
          _this.$notify({
                title: "成功",
                message: "已处理",
                type: "success"
              });
        });
      },
      handlePageChange (pageSize) {
        this.pageSize = pageSize;
        this.loaddeviceRepair(this.pageNo, this.pageSize);
      },
      handleNoChange (pageNo) {
        this.pageNo = pageNo;
        this.loaddeviceRepair(this.pageNo, this.pageSize);
      },
      handleTableChange (val) {
        this.multipleSelection = val;
      },

      
      loaddeviceRepair(pageNo, pageSize) {
        let _this = this;
        _this.loading = true;
      deviceRepairApi( {
          faultNo:_this.queryParams.faultNo,
          lockMac:_this.queryParams.lockMac,
          lockName:_this.queryParams.lockName,
          pageNo:pageNo,
          pageSize:pageSize,
          roleCode:this.roleCode
        }).then(resp => {
            if (resp.errmsg === "ok") {
              console.log(resp.data.dataList);
              _this.total = resp.data.totalNum;

              for (let i = 0; i < resp.data.dataList.length; i++) {
              
              let repairPersonLocal = resp.data.dataList[i].repairPerson.split(';');
              var repairPersonStr = '';
              for (let j = 0; j < repairPersonLocal.length; j++) {

                  repairPersonStr = repairPersonStr + repairPersonLocal[j].split(',')[1]+"; ";

              }

              resp.data.dataList[i].repairPerson = repairPersonStr.replace('undefined;','');

          }
              _this.list = resp.data.dataList;
            }
            setTimeout(() => {
            _this.loading = false;
          }, 1 * 1000);
        });
      },

      handleUpdate(row) {
      this.url = '';
      this.temp = Object.assign({}, row); // copy obj
      this.temp.timestamp = new Date(this.temp.timestamp);
      this.dialogStatus = "查看";
      this.dialogFormVisible = true;
      console.log('1111111111111111111111111111111',this.url);
      this.url = row.vehicleUrl;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },

    cancle2(){
      let _this = this;
      _this.addDialog2 = false;
    },
    Channelcheck2(){
      let _this = this;
      const data = {
          lockMac:_this.feeForm.lockMac,
          procRate:_this.feeForm.procRate,
          faultDesc:_this.feeForm.faultDesc,
          procMethod:_this.feeForm.procMethod == null ? "" : _this.feeForm.procMethod,
          isProced:_this.feeForm.isProced,
          repairPerson:_this.feeForm.repairPerson == null ? "" : _this.feeForm.repairPerson,
          id:_this.feeForm.id,
          liveImage:''
      };
      updateLcRepairProcApi(data).then(resp => {
        if (resp.errmsg === "ok") {
        _this.$notify({
                title: "修改成功",
                message: "已处理",
                type: "success"
              });
              _this.addDialog2 = false;
            }else{
              _this.$notify({
                title: "修改失败",
                message: "已处理",
                type: "success"
              });
            }
      
      })
      .catch(resp =>{
        _this.$notify({
                title: "修改失败",
                message: "已处理",
                type: "success"
              });
      })

    },
  
      queryBtn () {
        let _this = this;
        _this.loading = true;
        const data = {
          faultNo:_this.queryParams.faultNo,
          lockMac:_this.queryParams.lockMac,
          lockName:_this.queryParams.lockName,
          pageNo:_this.pageNo,
          pageSize:_this.pageSize,
      };
      deviceRepairApi(data).then(resp => {
        
          _this.total = resp.data.totalNum;
          _this.list = resp.data.dataList;
          _this.loading = false;
        });
      }
    },
    computed: {
      // userState () {
      //   return getNickName() === getTestUserName();
      // }
    },
    mounted: function () {
      let _this = this;
      _this.title = localStorage.getItem("title");
      _this.roleCode = localStorage.getItem("key");


      this.$nextTick(function () {
        this.loaddeviceRepair(_this.pageNo, _this.pageSize);
      });
    }
  }
  </script>
  
  <style scoped>
  .page-tool {
    background: rgb(237, 231, 231);
  }
  
  .page-tool div {
    text-align: right;
  }
  
  .lock-btn {
    margin-bottom: 5px;
    margin-top: -10px;
  }
  .operateBtn {
    font-size: 18px;
    width: 32px;
    height: 32px;
    padding: 0;
  }
  </style>